
    /*
    * 对选中的标签激活active状态，对先前处于active状态但之后未被选中的标签取消active
    * （实现左侧菜单中的标签点击后变色的效果）
    */

    $(document).ready(function () {
    getAllStaff()

    $('#menulist> a').click(function (e) {
    //e.preventDefault();    加上这句则导航的<a>标签会失效
    $('#menulist> a').removeClass('active');
    $(this).addClass('active');
});
});

    function getAllStaff() {
    $("#staffList").empty();
    $.ajax({
    url: "/staff/getAllStaff",
    type: "GET",
    dataType: "JSON",
    success: function(json) {
    var len=json.length
    for (let i=0;i<len;i++){
    var one=' <tr>\n' +
    '<td>#{sid}</td>\n' +
    '<td>#{name}</td>\n' +
    '<td>#{gender}</td>\n' +
    '<td>#{borth}</td>\n' +
    '<td>#{department}</td>\n' +
    '<td>#{education}</td>\n' +
    '<td>\n' +
    '<div class="btn-group">\n' +
    '<a href="javascript:void(0)" onclick="loadPageParam(\'personalSalary\',#{sid})" class="btn btn-primary">查看工资</a>'+
    '<a href="javascript:void(0)" onclick="loadPageParam(\'updateStaff\',#{sid})" class="btn btn-info">修改信息</a><a href="" onclick="deleteStaff(#{sid})" class="btn btn-danger">删除</a>\n' +
    '</div>\n' +
    '\n' +
    '</td>\n' +
    '</tr>'

    one=one.replace(/#{sid}/g, json[i].sid)
    one=one.replace(/#{name}/g, json[i].name)
    one=one.replace(/#{gender}/g, json[i].gender)
    one=one.replace(/#{borth}/g, json[i].borth)
    one=one.replace(/#{department}/g, json[i].department)
    one=one.replace(/#{education}/g, json[i].education)

    $("#staffList").append(one);
}
}
})
}

    function loadPage(url) {
    $.get(url,function(data,status){
        $("#right").html(data);
    });
}
    function loadPageParam(url,sid) {
        //点击修改时要把该员工的id一起带走传下去,为后面操作数据库提供条件根据
        //这里把sid传到控制器,控制器在使用thymleaf的model设置sid值就可以传到前端html代码了
        $.get(url,{sid:sid},function(data,status){
            $("#right").html(data);
        });
    }


    function searchByName(){
    var name = $("#searchName").val()
    $.ajax({
    url: "/staff/findByName",
    data:{"name":name},
    type: "POST",
    dataType: "JSON",
    success: function (json) {
    $("#staffList").empty();
    var one=' <tr>\n' +
    '<td>#{sid}</td>\n' +
    '<td>#{name}</td>\n' +
    '<td>#{gender}</td>\n' +
    '<td>#{borth}</td>\n' +
    '<td>#{department}</td>\n' +
    '<td>#{education}</td>\n' +
    '<td>\n' +
    '<div class="btn-group">\n' +
        '<a href="javascript:void(0)" onclick="loadPageParam(\'personalSalary\',#{sid})" class="btn btn-primary">查看工资</a>'+
    '<a href="javascript:void(0)" class="btn btn-info" onclick="loadPageParam(\'updateStaff\',#{sid})">修改信息</a><a href="" onclick="deleteStaff(#{sid})" class="btn btn-danger">删除</a>\n' +
    '</div>\n' +
    '\n' +
    '</td>\n' +
    '</tr>'

    one=one.replace(/#{sid}/g, json.sid)
    one=one.replace(/#{name}/g, json.name)
    one=one.replace(/#{gender}/g, json.gender)
    one=one.replace(/#{borth}/g, json.borth)
    one=one.replace(/#{department}/g, json.department)
    one=one.replace(/#{education}/g, json.education)

    $("#staffList").append(one);
},
    error:function (){
    alert("没有这个员工！")
}
})
}

    function deleteStaff(sid){
    $.ajax({
        url: "/staff/deleteStaff",
        data: {"sid": sid},
        type: "POST",
        dataType: "JSON",
        success: function () {
            alert("删除成功！")
        },
        error:function (){
            alert("删除失败！")
        }
    })
}

